package com.tcc.etec.mecashow;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;

import com.tcc.etec.mecashow.activity.TelaPrincipalActivity;

public class SplashActivity extends Activity{
	
	private View moveView;
	private View mecaView;
	private int mShortAnimationDuration;
	
	@Override
	protected void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
		
		setContentView(R.layout.splash_mecashow);
		
		mecaView = findViewById(R.id.meca_view);
		moveView = findViewById(R.id.move_view);
        mShortAnimationDuration = getResources().getInteger(android.R.integer.config_longAnimTime);
	}
	
	@Override
	protected void onStart() {
		super.onStart();
		new Handler().postDelayed(new Runnable() {
			
			@Override
			public void run() {
				crossfade();
				new Handler().postDelayed(new Runnable() {
					@Override
					public void run() {
						Intent intent = new Intent(getApplicationContext(), TelaPrincipalActivity.class);
						startActivity(intent);
					}
				}, 3000);
			}
		}, 3000);
		
		
	}
	
	private void crossfade() {
		// Exibe a imagem da torre
		mecaView.setAlpha(0f);
		mecaView.setVisibility(View.VISIBLE);
	    mecaView.animate().alpha(1f).setDuration(mShortAnimationDuration).setListener(null);

	    // Esconde o logo do Move
		moveView.animate().alpha(0f).setDuration(mShortAnimationDuration).setListener(new AnimatorListenerAdapter() {
					@Override
					public void onAnimationEnd(Animator animation) {
						moveView.setVisibility(View.GONE);
					}
		});
	}
}
